<script setup lang="ts">
import {
  useNotification,
  NotificationReactive
} from 'naive-ui'
import { getCurrent } from '@tauri-apps/api/window'
import { confirm } from '@tauri-apps/plugin-dialog'

const notification = useNotification()
let handler: NotificationReactive | undefined

getCurrent().onCloseRequested(async (event) => {
  const confirmed = await confirm('是否确定关闭程序?', {
    title: '确认操作',
    okLabel: '确定',
    cancelLabel: '取消'
  })
  if (!confirmed) {
    event.preventDefault()
  }
})

defineExpose({
  onError (err: Any) {
    // handler?.destroy()
    // handler = notification.error({
    //   title: '发生错误',
    //   content: err.message || err.toString?.() || err,
    //   duration: 0,
    //   closable: true
    // })
    console.error(err)
  }
})
window.addEventListener('contextmenu', evt => evt.preventDefault())
</script>

<template>
  <router-view v-slot="{ Component }">
    <keep-alive>
      <component class="page" :is="Component"></component>
    </keep-alive>
  </router-view>
</template>
<style lang="less">
html,
body {
  width: 100vw;
  height: 100vh;
  margin: 0;
  overflow: hidden;
  user-select: none;
  font-size: 16px;
  font-family: 微软雅黑, MicrosoftYaHei;
}

#app {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
  padding: 0;

  .n-config-provider {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .page {
    height: 100%;
  }
}
</style>
